package com.phkj.qdh.ui.adapter

import android.content.Context
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.phkj.qdh.R
import com.phkj.qdh.bean.UseCarMyBean

/**
 * 用车申请适配器
 */
class UseCarSubmitAdapter : BaseQuickAdapter<UseCarMyBean, QuickViewHolder>() {
    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: UseCarMyBean?) {
        val tvKey = holder.getView<TextView>(R.id.tv_key)
        tvKey.maxLines = 1
        val sb = StringBuilder()
        item?.ysNameList?.forEach {
            sb.append(it)
            sb.append("、")
        }
        tvKey.text = if (sb.isNotEmpty()) sb.deleteCharAt(sb.length - 1).toString() else ""
        holder.setText(R.id.tv_time, item?.applyDateStr)

        val state = holder.getView<ImageView>(R.id.iv_state)
        when (item?.applyStatus) {
            0 -> {
                Glide.with(context).load(R.mipmap.car_use_wait).into(state)
            }

            1 -> {
                Glide.with(context).load(R.mipmap.car_use_agree).into(state)
            }

            2 -> {
                Glide.with(context).load(R.mipmap.car_use_disagree).into(state)
            }
            else->{
                Glide.with(context).load(R.mipmap.car_use_finish).into(state)
            }
        }
    }

    override fun onCreateViewHolder(
        context: Context, parent: ViewGroup, viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.item_use_car_submit, parent)
    }
}